﻿using System;
using Core.Framework.Model.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Core.DataAccess.Model.Project.Entrepot
{
    /// <summary>
    /// 仓库模块
    /// </summary>
    public partial class ProjectEntrepotContext : DbContext
    {
        public ProjectEntrepotContext()
        {
        }

        public ProjectEntrepotContext(DbContextOptions<ProjectEntrepotContext> options)
            : base(options)
        {
        }

        public virtual DbSet<EntrepotLog> EntrepotLog { get; set; }
        public virtual DbSet<ProductParams> ProductParams { get; set; }
        public virtual DbSet<ProductParamsDic> ProductParamsDic { get; set; }
        public virtual DbSet<ProductPurchase> ProductPurchase { get; set; }
        public virtual DbSet<ProductSell> ProductSell { get; set; }
        public virtual DbSet<ProductSku> ProductSku { get; set; }
        public virtual DbSet<ProductTemplate> ProductTemplate { get; set; }
        public virtual DbSet<ProductAttrbute> ProductAttrbute { get; set; }
        public virtual DbSet<ProductType> ProductType { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder
                    // 数据操作日志
                    .UseLoggerFactory(EFLogger.GetLoggerFactory())
                    .UseSqlServer(CoreStartupHelper.GetConnectionValue("Entrepot_SqlServerConnection"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<EntrepotLog>(entity =>
            {
                entity.ToTable("entrepot_log");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.CountStock)
                    .HasColumnName("count_stock")
                    .HasColumnType("decimal(18, 3)");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.PurchaseKey).HasColumnName("purchase_key");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.TemplateKey).HasColumnName("template_key");
            });

            modelBuilder.Entity<ProductParams>(entity =>
            {
                entity.ToTable("product_params");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey)
                    .HasColumnName("user_key")
                    .HasDefaultValueSql("((0))");
            });

            modelBuilder.Entity<ProductParamsDic>(entity =>
            {
                entity.ToTable("product_params_dic");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.ParamsKey).HasColumnName("params_key");

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey)
                    .HasColumnName("user_key")
                    .HasDefaultValueSql("((0))");
            });

            modelBuilder.Entity<ProductPurchase>(entity =>
            {
                entity.ToTable("product_purchase");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.CountStock)
                    .HasColumnName("count_stock")
                    .HasColumnType("decimal(18, 3)");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.PurchaseKey).HasColumnName("purchase_key");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SkuKey).HasColumnName("sku_key");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.TemplateKey).HasColumnName("template_key");
            });

            modelBuilder.Entity<ProductSell>(entity =>
            {
                entity.ToTable("product_sell");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.CountStock)
                    .HasColumnName("count_stock")
                    .HasColumnType("decimal(18, 3)");

                entity.Property(e => e.OrderKey).HasColumnName("order_key");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SkuKey).HasColumnName("sku_key");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.TemplateKey).HasColumnName("template_key");
            });

            modelBuilder.Entity<ProductSku>(entity =>
            {
                entity.ToTable("product_sku");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.CostPrice)
                    .HasColumnName("cost_price")
                    .HasColumnType("decimal(18, 5)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.CountStock)
                    .HasColumnName("count_stock")
                    .HasColumnType("decimal(18, 3)");

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SalesConfirm)
                    .HasColumnName("sales_confirm")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.SalesPrice)
                    .HasColumnName("sales_price")
                    .HasColumnType("decimal(18, 5)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.TemplateKey).HasColumnName("template_key");

                entity.Property(e => e.UpSupplierKey).HasColumnName("up_supplier_key");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<ProductTemplate>(entity =>
            {
                entity.ToTable("product_template");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Confirm)
                    .HasColumnName("confirm")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.SupplierKey).HasColumnName("supplier_key");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.TypeKey).HasColumnName("type_key");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");
            });

            modelBuilder.Entity<ProductType>(entity =>
            {
                entity.ToTable("product_type");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(11)
                    .IsUnicode(false);

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Title)
                    .HasColumnName("title")
                    .HasMaxLength(15)
                    .IsUnicode(false);

                entity.Property(e => e.UpKey)
                    .HasColumnName("up_key")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.UpdateLastTime)
                    .HasColumnName("update_last_time")
                    .HasColumnType("datetime");

                entity.Property(e => e.UserKey)
                    .HasColumnName("user_key")
                    .HasDefaultValueSql("((0))");
            });
        }
    }
}
